import { createSlice } from '@reduxjs/toolkit'
import { getReportInfoAPI } from '@/api/report'
const reportStore = createSlice({
  name: 'report',
  // 数据状态
  initialState: {
    reportInfo: []
  },
  // 同步修改方法
  reducers: {
    setReportInfo (state, action) {
      state.reportInfo = action.payload
    }
  }
})

// 解构出actionCreater
const { setReportInfo } = reportStore.actions

// 获取reducer函数
const reportReducer = reportStore.reducer

// 异步封装,获取token
const fetchReportInfo = () => {
  return async (dispatch) => {
    const res = await getReportInfoAPI()
    dispatch(setReportInfo(res.data))
  }
}

export { fetchReportInfo }

export default reportReducer